﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace JXT.PrimaryKey.Batman.Core.Configuration
{
    /// <summary>
    /// 数据库连接配置集合
    /// </summary>
    public class ServiceConnectionSettingConfigurationElementCollection : ConfigurationElementCollection
    {
        /// <summary>
        /// 默认配置节点
        /// </summary>
        [ConfigurationProperty("defaultConnectionString", IsRequired = true)]
        public string DefaultConnectionString
        {
            get { return base["defaultConnectionString"] as string; }
            set { base["defaultConnectionString"] = value; }
        }

        public new ServiceConnectionSettingConfigurationElement this[string name]
        {
            get
            {
                return BaseGet(name) as ServiceConnectionSettingConfigurationElement;
            }
            set
            {
                if (BaseGet(name) != null)
                {
                    base.BaseRemove(name);
                }
                BaseAdd(value);
            }
        }

        protected override ConfigurationElement CreateNewElement()
        {
            return new ServiceConnectionSettingConfigurationElement();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((ServiceConnectionSettingConfigurationElement)element).Name;
        }
    }
}
